package br.com.quiz.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.quiz.domain.Aluno;
import br.com.quiz.domain.Disciplina;
import br.com.quiz.util.HibernateUtil;

public abstract class DisciplinaDAO{
	public static List< Disciplina > listar() {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		List< Disciplina > disciplinas = null;
		try {
			Query consulta = sessao.getNamedQuery( "Disciplina.listar" );
			disciplinas = consulta.list();
		} catch ( RuntimeException e ) {
			throw e;
		} finally {
			sessao.close();
		}

		return disciplinas;
	}

	public static Disciplina filtrarPorId( int disId ) {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		Disciplina disciplina = null;
		try {
			Query consulta = sessao.getNamedQuery( "Disciplina.filtrarPorId" );
			consulta.setInteger( "disId", disId );
			disciplina = (Disciplina) consulta.uniqueResult();
		} catch ( RuntimeException e ) {
			throw e;
		} finally {
			sessao.close();
		}

		return disciplina;
	}
}
